import { FilterSpecification } from 'mapbox-gl';
import { BaseLayer, IBaseLayerParams, RenderOptions } from './BaseLayer';

/**
 * 图标图层
 * 前置步骤
 * 1. map.addSource
 * 2. map.loadImages
 */
export class IconLayer extends BaseLayer {
  iconOptions: RenderOptions = {};
  constructor(cfg: IBaseLayerParams, iconOptions?: RenderOptions) {
    super(cfg);
    this.iconOptions = iconOptions || {};
  }

  filter(conditions: FilterSpecification) {
    return this.map.setFilter(this.layerId, conditions);
  }

  addToMap(): string {
    this.map.addLayer({
      id: this.layerId,
      type: 'symbol',
      source: this.sourceId,
      ...this.iconOptions,
    });
    return this.layerId;
  }
}
